﻿using Dapper;
using Max.PH6_2009A.LowCode.Common;
using Max.PH6_2009A.LowCode.DataAccess;
using Max.PH6_2009A.LowCode.IRespository;
using System.Data;

namespace Max.PH6_2009A.LowCode.Respository
{
    public class BaseRespository<T> : IBaseRespository<T> where T : class, new()
    {
        DapperFactory _factory;
        IDbConnection _db;
        public BaseRespository(DapperFactory factory)
        {
            _factory = factory;
            _db = _factory.GetIDbConnection();
        }

        public int Execute(string sql,object param,IDbTransaction transaction=null)
        {
           return  _db.Execute(sql, param, transaction);

        }
        
        public IEnumerable<T> Query(string sql,object param)
        {           
            var result = _db.Query<T>(sql,param);
            return result;
        }

        public IEnumerable<T> Query(string sql, object param, CommandType commandType)
        {
            var result = _db.Query<T>(sql, param,commandType:commandType);
            return result;
        }
    }
}